# !/usr/bin/env python
# -*- coding: utf-8 -*-

#  Reference: https://www.cnblogs.com/picassooo/p/13533433.html
#  Usage: Example for solving assignment problem with scipy.

from scipy.optimize import linear_sum_assignment
import numpy as np

cost = np.array([[4, 1, 3, 6], [2, 0, 5, 1], [3, 2, 2, 8], [4, 3, 2, 9]])
cost = cost
row_ind, col_ind = linear_sum_assignment(cost)
print('row_ind:')
print(row_ind)  # 人员号
print('col_ind:')
print(col_ind)  # 对应的最优指派任务
print('benefit:')
print(cost[row_ind, col_ind])  # 每项任务花费的时间
print('benefit_sum:')
print(cost[row_ind, col_ind].sum())  # 所有任务耗费的时间